<?php
/**
 * Created by PhpStorm.
 * User: xiao
 * Date: 2017/6/15
 * Time: 下午5:19
 */

namespace app\src\accountScore\logic;


use app\src\accountScore\model\AccountScoreHistory;
use app\src\base\logic\BaseLogic;

class AccountScoreHistoryLogic extends BaseLogic
{
    const SCORE_MINUS = 1;
    const SCORE_PLUS = 2;
    const SCORE_SET = 3;

    protected function _init()
    {
        $this->setModel(new AccountScoreHistory());
    }

    /**
     * 添加积分变动记录
     * @param $type
     * @param $account_id
     * @param $score_type
     * @param $change_type
     * @param string $reason
     * @return array
     */
    public function addHistory($type, $account_id, $score_type, $change_type, $before_score, $after_score, $reason = '')
    {
        $data = [
            'type' => $type,
            'account_id' => $account_id,
            'score_type' => $score_type,
            'change_type' => $change_type,
            'before_score' => $before_score,
            'after_score' => $after_score,
            'reason' => $reason,
            'create_time' => NOW_TIME
        ];

        $result = $this->add($data);
        if($result['status']){
            return $this->apiReturnSuc('success');
        }else{
            return $this->apiReturnErr($result['info']);
        }
    }
}